﻿//创建时间: 2011-1-24
//创建作者: 李 城
//功能说明: 用户操作 映射
//最后修改: 2011-1-24
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Reflection;
using TRPOP.Common;
using TRPOP.Config;
using TRPOP.CMS.Model;

namespace TRPOP.CMS.Plugin
{
    /// <summary>
    /// 模板引擎映射
    /// </summary>
    public class ITemplateAccess
    {
        /// <summary>
        /// 获取模板数据处理的程序集
        /// </summary>
        /// <returns></returns>
        public static IDAL GetIDalInstance()
        {
            /*
             * 
             * 之前的实现方式 lcheng 2011.07.07
             * 
            ICache oICache = ICacheAccess.GetInstance();
            if (oICache.IsExist(CacheKeys.Sys_ITemplateDal) == false)
            {
                IDAL oIDAL = (IDAL)Assembly.Load(CMSConfig.DALSQLInstanceForTemplate).CreateInstance(CMSConfig.DALClassNameForTemplate);
                oICache.Save(CacheKeys.Sys_ITemplateDal,
                               oIDAL,
                               CacheKeys.SysAssemblyTimeSecond);
                return oIDAL;
            }
            return (IDAL)oICache.Read(CacheKeys.Sys_ITemplateDal);
            */
            return CacheHelper.GetByICache<IDAL>(
                    CacheKeys.Sys_ITemplateDal,
                    CacheKeys.SysAssemblyTimeSecond,
                    ICacheAccess.GetInstance(),
                    () =>
                    {
                        return (IDAL)Assembly.Load(SystemInfoHelper.getSystemInfo().NameSpaceForTemplateDal).CreateInstance(SystemInfoHelper.getSystemInfo().ClassNameForTemplateDal);
                    }
            );

        }
        /// <summary>
        /// 获取模板函数处理的程序集
        /// </summary>
        /// <returns></returns>
        public static IFunc GetIFuncInstance()
        {
            /*
             * 2011.07.28 修改 下面的这种方式不利于以后统一的修改，所以注释掉，换做新的 CacheHelper.GetByICache 的方法
             * 
            ICache oICache = ICacheAccess.GetInstance();
            if (oICache.IsExist(CacheKeys.Sys_ITemplateFunc) == false)
            {
                IFunc oIFunc = (IFunc)Assembly.Load(CMSConfig.CMSCommonInstance).CreateInstance(CMSConfig.CMSCommonInstanceForTemplate);
                oICache.Save(CacheKeys.Sys_ITemplateFunc,
                              oIFunc,
                               CacheKeys.SysAssemblyTimeSecond);
                return oIFunc;
            }
            return (IFunc)oICache.Read(CacheKeys.Sys_ITemplateFunc);
            */
            return CacheHelper.GetByICache<IFunc>(
                            CacheKeys.Sys_ITemplateFunc,
                            CacheKeys.SysAssemblyTimeSecond,
                            ICacheAccess.GetInstance(),
                            () =>
                            {
                                return (IFunc)Assembly.Load(SystemInfoHelper.getSystemInfo().NameSpaceForTemplateFunc).CreateInstance(SystemInfoHelper.getSystemInfo().ClassNameForTemplateFunc);
                            }
            );
        }
    }
}
